package com.eleme.food.controller;

import com.eleme.food.dto.FoodAddDTO;
import com.eleme.food.dto.FoodUpdateDTO;
import com.eleme.food.service.FoodService;
import com.eleme.food.vo.FoodVO;
import com.eleme.food.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/FoodController")
public class FoodController {
    @Autowired
    private FoodService foodService;

    @PostMapping("/add")
    public Result<String> addFood(@Validated @RequestBody FoodAddDTO dto) {
        return Result.success(foodService.addFood(dto));
    }

    @PostMapping("/update")
    public Result<String> updateFood(@Validated @RequestBody FoodUpdateDTO dto) {
        return Result.success(foodService.updateFood(dto));
    }

    @PostMapping("/status/{foodId}")
    public Result<String> changeStatus(@PathVariable String foodId, @RequestParam Integer status) {
        return Result.success(foodService.changeStatus(foodId, status));
    }

    @GetMapping("/list")
    public Result<List<FoodVO>> listAll() {
        return Result.success(foodService.listAll());
    }

    @GetMapping("/listFoodByBusinessId/{businessId}")
    public Result<List<FoodVO>> listFoodByBusinessId(@PathVariable("businessId") Integer businessId) {
        return Result.success(foodService.listByBusiness(businessId.toString()));
    }

    @GetMapping("/{foodId}")
    public Result<FoodVO> getById(@PathVariable String foodId) {
        return Result.success(foodService.getById(foodId));
    }
} 